package com.personal.website.lottery.table

import java.util
import scala.collection.JavaConverters._

/**
 * Created by Gavin on 2015/12/14.
 */
class EightDigitTable(issue: Int,redBalls: Seq[Int], blueBall: Int) extends Table(issue,redBalls,blueBall){
  override def createRecord(): Seq[Int] = EightDigitTable.ALL_EXISTS_BALLS.map(ball => if(redBalls.contains(ball)) ball else DEFAULT_NON_EXISTS_VALUE )

  override def toString: String = Seq(Seq(issue),Seq(createSum()),createRecord()).flatten.mkString(";")
}

object EightDigitTable{
  def apply(issue: Int,redBalls: Seq[Int], blueBall: Int) = new EightDigitTable(issue,redBalls,blueBall)
  def apply(issue: Int,allBalls: Seq[Int]) = new EightDigitTable(issue,allBalls.init,allBalls.last)
  def newInstance(issue: Integer,redBalls: util.List[Integer],blueBall: Integer) = new EightDigitTable(issue.toInt, redBalls.asScala.map(_.toInt),blueBall.toInt)

  val ALL_EXISTS_BALLS = (1 to 8).flatMap(digit => (1 to 32).filter(_ % 8 == digit % 8).map(n => if(n > 16) n + 1 else n)) :+ 17
  val headString = Seq("issue","sum","first","second","third","four","five","six","seven","eight","17")
}
